Percepts of AtCoder 2 - 洛谷

Percepts of AtCoder 2 - 洛谷 | 计算机科学教育新生态

这个题有 1500 score 得了 225,可以了,不用过于深入

void solve()
{
    ll x;
    cin >> x;
    bitset<64> a(x);

    int idx = 63;
    for (int i = 63; i >= 0; i--)
        if (a[i])
        {
            idx = i;
            break;
        }
        
    vector<int> ans(__lg(x) + 1, 0);
    for (int j = 1; j <= idx; j++)
        ans[j] = j;
    for (int i = idx - 1; i >= 0; i--)
        if (a[i])
            ans.insert(ans.begin() + i + 1, ++idx);

    cout << ans.size() - 1 << '\n';
    for (int i = 1; i < ans.size(); i++)
        cout << ans[i] << " ";
    cout << "\n";
}